<?php

namespace App\Console\Commands;

use App\Models\InvestmentMeeting;
use App\Models\Manufacturer;
use App\Services\ImageServices;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class RebuildCardCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'rebuild:card {id}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $id = $this->argument('id');
        $meeting_info = InvestmentMeeting::find($id);
        $lists = Manufacturer::query()->with(['category:id,name', 'person:id,name,nickname'])->where('investment_meeting_id', $id)->where('status', 1)->get();
        foreach ($lists as $item) {
            Log::info('生成邀请函', ['data' => $item->toArray()]);
            ImageServices::buildInvite($meeting_info, $item);
            ImageServices::buildCard($meeting_info, $item);
        }
        return Command::SUCCESS;
    }
}
